package LinesAndDotes;

public class Game implements IGame {
	char[][] matrix;

	public void generateMatrix(int x, int y) {
		matrix = new char[x * 2][y * 2];
		for (int i = 0; i < matrix.length; i++) {
			if (i % 2 == 0) {
				for (int j = 0; j < matrix[0].length; j++) {
					if (j % 2 == 0)
						matrix[i][j] = '.';
					else
						matrix[i][j] = ' ';
				}
			} else {
				for (int j = 0; j < matrix[0].length; j++) {
					if (j % 2 == 0)
						matrix[i][j] = ' ';
					else
						matrix[i][j] = ' ';
				}
			}
		}
	}

	public void printMatrix() {
		System.out.print("  ");
		for (int i = 0; i < matrix[0].length / 2; i++) {
			System.out.print(i + " ");
		}
		System.out.println();
		for (int i = 0; i < matrix.length - 1; i++) {
			if (i % 2 == 0) {
				System.out.print((i / 2) + " ");
			} else
				System.out.print("  ");
			for (int j = 0; j < matrix[0].length - 1; j++) {
				System.out.print(matrix[i][j]);
			}

			System.out.println();
		}

	}

	@Override
	public void startGame() {
		// TODO Auto-generated method stub

	}

	@Override
	public void addVerticalLine(int c, int n, int m) {
		c = c * 2;
		n = n * 2;
		m = m * 2;
		if (n < matrix[0].length && m < matrix[0].length) {
			if (n < m && matrix[n + 1][c] != '|')
				matrix[n + 1][c] = '|';
			if (n > m && matrix[m + 1][c] != '|')
				matrix[m + 1][c] = '|';
		} else
			System.out.println(" Ima liniq! ");
	}

	@Override
	public void addHorizontalLine(int r, int n, int m) {
		r = r * 2;
		n = n * 2;
		m = m * 2;
		if (n < matrix.length && m < matrix[0].length
				&& matrix[r][m - 1] != '_' && matrix[r][n - 1] != '_') {
			if (n < m)
				matrix[r][m - 1] = '_';
			else
				matrix[r][n - 1] = '_';
		} else
			System.out.println("Ima liniq!");
	}

	@Override
	public boolean isBoxClosed() {
		// TODO Auto-generated method stub
		return false;
	}
}